package com.psdi.manager;
import com.psdi.element.Position;
import com.psdi.element.Size;
import com.psdi.window.GameJFrame;


import java.util.*;

/**
 * 敌人系统类
 * 用于管理游戏中的敌人生成和逻辑处理
 */
public class EnemySystem {
    private int maxOption = 6;//敌人最大容量
    public int curruntNum = 0;//敌人当前容量
    private static EnemySystem INSTANCE = null;

    private EnemySystem() {

    }

    public static synchronized EnemySystem getINSTANCE() {
        if (INSTANCE == null) {
            INSTANCE = new EnemySystem();
        }
        return INSTANCE;
    }
    //从四个角落生成
    public void creatlogic1(){
        while(this.curruntNum < maxOption){
            curruntNum++;
            Random random = new Random();
            int[] Xranges = {30, GameJFrame.GAME_WIDTH - 30};
            int[] Yranges = {30, GameJFrame.GAME_HEIGHT - 30};
            int selectedRangeX = random.nextInt(2);
            int selectedRangeY = random.nextInt(2);
            int X = Xranges[selectedRangeX];
            int Y = Yranges[selectedRangeY];
            int x = random.nextInt(70) + X;
            int y = random.nextInt(70) + Y;
            GameLoader.LoadEnemy(new Position(x,y),4f,0.5f);
        }
    }
    //数量翻倍
    public void creatlogic2(){
        while(this.curruntNum < 2*maxOption){
            curruntNum++;
            Random random = new Random();
            int[] Xranges = {30, GameJFrame.GAME_WIDTH - 30};
            int[] Yranges = {30, GameJFrame.GAME_HEIGHT - 30};
            int selectedRangeX = random.nextInt(2);
            int selectedRangeY = random.nextInt(2);
            int X = Xranges[selectedRangeX];
            int Y = Yranges[selectedRangeY];
            int x = random.nextInt(100) + X;
            int y = random.nextInt(100) + Y;

            GameLoader.LoadEnemy(new Position(x,y),64f,0.6f);
        }
    }
    //多方位生成且数量加倍
    public void creatlogic3(int num){

        while(this.curruntNum < num*maxOption){
            int x=0,y=0;
            curruntNum++;
            Random random = new Random();
            int X=random.nextInt(4);
            switch (X){
                case 0:{
                    x = random.nextInt(GameJFrame.GAME_WIDTH - 30) + 30;
                    y= 30;
                    break;
                }
                case 1:{
                    x = 30;
                    y= random.nextInt(GameJFrame.GAME_HEIGHT - 30) + 30;
                    break;
                }
                case 2:{
                    x = random.nextInt(GameJFrame.GAME_WIDTH - 30) + 30;
                    y= GameJFrame.GAME_HEIGHT - 30;
                    break;
                }
                case 3:{
                    x = GameJFrame.GAME_WIDTH - 30;
                    y= random.nextInt(GameJFrame.GAME_HEIGHT - 30) + 30;
                    break;
                }

            }
            GameLoader.LoadEnemy(new Position(x,y),128f,0.75f);
        }
    }
    public void createEnemys(String string){
        switch (string){
            case "第一波": creatlogic1();break;
            case "第二波": creatlogic2();break;
            case "第三波": creatlogic3(4);break;
        }
        if(string.equals("第二关")){
            GameLoader.LoadBoss(new Position((float) GameJFrame.GAME_WIDTH /2-75,0),10000  ,new Size(150,150));
        }
        if(string.equals("第一波第二关")){
            creatlogic3(2);
        }
    }
}
